<?php
//	require_once '../query/dbquery.php';
	require_once '../query/config.php';
	$posts = $_REQUEST['posts'];
	if ( isset($posts) && $posts == "add" ){
		$postsname	= $_REQUEST['postsname'];
		$temps 		= $_REQUEST['temps'];
		$num2		= $_REQUEST['num2'];
		$num3		= $_REQUEST['num3'];
		$num4	 	= $_REQUEST['num4'];
		$closetime	= $_REQUEST['closetime'];
		$issuetime	= $_REQUEST['issuetime'];
		$opt		= $_REQUEST['opt'];
		$order		= $_REQUEST['order'];
		$sang		= $_REQUEST['sang'];
			
		$id 		= $_REQUEST['id'];
		$cdate	=  $mdate = date('Y-m-d');				
		$publish 	= 1;
		
		new dbConnect();
		if ($id == 0){
			$query = "INSERT INTO `tposts` SET `name` = '".$postsname."', `temps` = '".$temps."',`num2` = '".$num2."', `num3` = '".$num3."'".
					", `num4` = '".$num4."', `closetime` = '".$closetime."', `issuetime` = '".$issuetime."', `opt` = '".$opt."'".
					", `order` = '".$order."', `sang` = '".$sang."'".
					", `cdate` = '".$cdate."', `publish` = $publish";	
			if (mysql_query($query)){
				echo mysql_insert_id();
			}else{
				echo "0";
			}
		}else{			
			$query = "UPDATE `tagent` SET SET `name` = '".$postsname."', `temps` = '".$temps."',`num2` = '".$num2."', `num3` = '".$num3."'".
					", `num4` = '".$num4."', `closetime` = '".$closetime."', `issuetime` = '".$issuetime."', `opt` = '".$opt."'".
					", `order` = '".$order."', `sang` = '".$sang."'".
					", `cdate` = '".$cdate."', `publish` = $publish  WHERE `id`='".$id."'";
			//echo $query;	
			if (mysql_query($query)){
				echo $id;
			}else{
			  	echo "0";
			}
		} 
	}elseif( isset($posts) && $posts == "getPosts" ){
		$id 		= $_REQUEST['id'];
		new dbConnect();
		$query = "SELECT * FROM `tposts` WHERE publish = 1 and id = ".$id;
		$res = mysql_query($query);
		echo json_encode(mysql_fetch_object($res));		
	}
?>